﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//
using Triunfadores.BusinessEntities;
using Triunfadores.Repository.Mapping;

namespace Triunfadores.Repository
{
    public partial class TriunfadoresContext:DbContext
    {
        //public TriunfadoresContext()
        //{
        //    //cuando ya exite la db
        //    //Database.SetInitializer<TriunfadoresContext>(null);
        //    //para que se cree si no existe
        //    //Database.SetInitializer<TriunfadoresContext>(new CreateDatabaseIfNotExists<TriunfadoresContext>());
        //    //cada vez que hay un cambio se modifica la db
        //    Database.SetInitializer<TriunfadoresContext>(new DropCreateDatabaseIfModelChanges<TriunfadoresContext>());
        //}

        static TriunfadoresContext()
        {
            Database.SetInitializer<TriunfadoresContext>(
                new DropCreateDatabaseIfModelChanges<TriunfadoresContext>()
                //CreateDatabaseIfNotExists<TriunfadoresContext>()
                );
        }

        public TriunfadoresContext() : base("Name=TriunfadoresContext")
        {
            this.Configuration.ProxyCreationEnabled = false;
        }

        public DbSet<Accion> Acciones { get; set; }
        public DbSet<Ahorro> Ahorros { get; set; }
        public DbSet<Beneficiario> Beneficiarios { get; set; }
        public DbSet<Cliente> Clientes { get; set; }
        public DbSet<CuotaPago> CuotaPagos { get; set; }
        public DbSet<DetalleCliente> DetallesClientes { get; set; }
        public DbSet<DetalleVentaAccion> DetalleVentaAccions { get; set; }
        public DbSet<Prestamo> Prestamos { get; set; }
        public DbSet<SolicitudAhorro> SolicitudAhorros { get; set; }
        public DbSet<SolicitudPrestamo> SolicitudPrestamos { get; set; }
        public DbSet<TipoCliente> TipoClientes { get; set; }
        public DbSet<Ubigeo> Ubigeos { get; set; }
        public DbSet<VentaAccion> VentaAcciones  { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new AccionMap());
            modelBuilder.Configurations.Add(new AhorroMap());
            modelBuilder.Configurations.Add(new BeneficiarioMap());
            modelBuilder.Configurations.Add(new ClienteMap());
            modelBuilder.Configurations.Add(new CuotaPagoMap());
            modelBuilder.Configurations.Add(new DetalleClienteMap());
            modelBuilder.Configurations.Add(new DetalleVentaAccionMap());
            modelBuilder.Configurations.Add(new PrestamoMap());
            modelBuilder.Configurations.Add(new SolicitudAhorroMap());
            modelBuilder.Configurations.Add(new SolicitudPrestamoMap());
            modelBuilder.Configurations.Add(new TipoClienteMap());
            modelBuilder.Configurations.Add(new UbigeoMap());
            modelBuilder.Configurations.Add(new VentaAccionMap());
        }
    }
}
